package com.huang.Controller;

import com.huang.Pojo.Product;
import com.huang.Service.Feign;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import javax.annotation.Resource;

@RestController
public class controller01 {

    @Resource
    private Feign feign;

    @Resource
    private RestTemplate restTemplate;

    @Autowired
    private RocketMQTemplate rocketMQTemplate;

    public static final String Default_url = "http://service-product";

    @GetMapping(value = "/controller1/{pid}")
    public Product controller1(@PathVariable("pid") Integer pid){
        Product product = feign.product(pid);
        return product;
    }


    @GetMapping(value = "/controller2/{pid}")
    public Product controller2(@PathVariable("pid") Integer pid){
        Product product = restTemplate.getForObject(Default_url + "/product/" + pid, Product.class);
        rocketMQTemplate.convertAndSend("order-topic", product);
        return product;
    }

}
